package com.ophiux.FeverManagement.aplication.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.FeverManagement.aplication.bean.getTreatmentListRequest;
import com.ophiux.FeverManagement.aplication.bean.getTreatmentListResponse;
import com.ophiux.FeverManagement.aplication.service.IGetTreatmentListAppPort;
import com.ophiux.FeverManagement.domain.entity.RbTreatment;
import com.ophiux.FeverManagement.domain.repository.ITreatmentRepository;
import com.ophiux.micro.core.application.Result;
import com.ophiux.micro.core.application.ResultEnum;
import com.ophiux.utils.parser.AssemblyFactory;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class GetTreatmentListAppService implements IGetTreatmentListAppPort{
	
	@Autowired
	ITreatmentRepository treatmentRepository;

	@Override
	public Result<List<getTreatmentListResponse>> execute(getTreatmentListRequest request) {
		try {
			if (!request.isParamValid()) {
				return Result.fail(ResultEnum.requestParamFail);
			}
			
			Map<String,String> map = new HashMap<String,String>();
			map.put("TITLE", request.getTITLE());
			
			List<RbTreatment> list = treatmentRepository.selectAll(map);
			
			List<getTreatmentListResponse> resp = AssemblyFactory.instance().parse(list, getTreatmentListResponse.class);

			return Result.success(resp);
		} catch (Exception e) {
			log.info("GetTreatmentListAppService=》execute(),程序异常：", e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
	}

}
